#include <tsin/runtime/CharacterBlitWork.hpp>

#include <tsin/runtime/GameRuntime.hpp>
#include <tsin/runtime/Player.hpp>

#include <tsin/display/Display.hpp>
#include <tsin/display/Image.hpp>
#include <tsin/display/DecoratedImage.hpp>
#include <tsin/library/Game.hpp>

#include <tsin/util/Set.hpp>
#include <tsin/util/Logger.hpp>
#include <tsin/util/MemCheck.hpp>
using namespace tsin;

CharacterEarlyBlitWork::CharacterEarlyBlitWork()
{
}

CharacterEarlyBlitWork::~CharacterEarlyBlitWork()
{
        for (player_set->toBegin(); !player_set->atEnd(); player_set->next()) {
                delete player_set->remove();
        }
}

void CharacterEarlyBlitWork::init(GameRuntime *runtime)
{
        this->display = &runtime->display;
        this->viewport = runtime->game->getViewport(0);

        player_set = runtime->players;
}

int CharacterEarlyBlitWork::run()
{
        display->useViewportFrame(*viewport);
        for (player_set->toBegin(); !player_set->atEnd(); player_set->next()) {
                Player *player = player_set->get();
                player->checkEvents(true);
        }
        return 0;
}

CharacterLateBlitWork::CharacterLateBlitWork()
{
}

CharacterLateBlitWork::~CharacterLateBlitWork()
{
}

void CharacterLateBlitWork::init(GameRuntime *runtime)
{
        this->display = &runtime->display;
        this->viewport = runtime->game->getViewport(0);

        player_set = runtime->players;
}

int CharacterLateBlitWork::run()
{
        display->useViewportFrame(*viewport);
        for (player_set->toBegin(); !player_set->atEnd(); player_set->next()) {
                Player *player = player_set->get();
                player->checkEvents(false);
        }
        return 0;
}
